<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable=no">
  <meta name="description" content="API docs for the request method from the HttpRequest class, for the Dart programming language.">
  <title>request method - HttpRequest class - dart:html library - Dart API</title>
  <!-- required because all the links are pseudo-absolute -->
  <base href="../..">

  <link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500,400i,400,300|Source+Sans+Pro:400,300,700" rel="stylesheet">
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <link rel="stylesheet" href="static-assets/github.css">
  <link rel="stylesheet" href="static-assets/styles.css">
  <link rel="icon" href="static-assets/favicon.png">
  <!-- header placeholder -->
</head>

<body>

<div id="overlay-under-drawer"></div>

<header id="title">
  <button id="sidenav-left-toggle" type="button">&nbsp;</button>
  <ol class="breadcrumbs gt-separated dark hidden-xs">
    <li><a href="index.html">flutter_form_builder</a></li>
    <li><a href="dart-html/dart-html-library.html">dart:html</a></li>
    <li><a href="dart-html/HttpRequest-class.html">HttpRequest</a></li>
    <li class="self-crumb">request method</li>
  </ol>
  <div class="self-name">request</div>
  <form class="search navbar-right" role="search">
    <input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
  </form>
</header>

<main>

  <div id="dartdoc-sidebar-left" class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left">
    <header id="header-search-sidebar" class="hidden-l">
      <form class="search-sidebar" role="search">
        <input type="text" id="search-sidebar" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
      </form>
    </header>
    
    <ol class="breadcrumbs gt-separated dark hidden-l" id="sidebar-nav">
      <li><a href="index.html">flutter_form_builder</a></li>
      <li><a href="dart-html/dart-html-library.html">dart:html</a></li>
      <li><a href="dart-html/HttpRequest-class.html">HttpRequest</a></li>
      <li class="self-crumb">request method</li>
    </ol>
    
    <h5>HttpRequest class</h5>
    <ol>
    
        <li class="section-title"><a href="dart-html/HttpRequest-class.html#constructors">Constructors</a></li>
        <li><a href="dart-html/HttpRequest/HttpRequest.html">HttpRequest</a></li>
    
        <li class="section-title">
            <a href="dart-html/HttpRequest-class.html#instance-properties">Properties</a>
        </li>
        <li><a href="dart-html/HttpRequest/onReadyStateChange.html">onReadyStateChange</a></li>
        <li><a href="dart-html/HttpRequest/readyState.html">readyState</a></li>
        <li><a href="dart-html/HttpRequest/response.html">response</a></li>
        <li><a href="dart-html/HttpRequest/responseHeaders.html">responseHeaders</a></li>
        <li><a href="dart-html/HttpRequest/responseText.html">responseText</a></li>
        <li><a href="dart-html/HttpRequest/responseType.html">responseType</a></li>
        <li><a href="dart-html/HttpRequest/responseUrl.html">responseUrl</a></li>
        <li><a href="dart-html/HttpRequest/responseXml.html">responseXml</a></li>
        <li><a href="dart-html/HttpRequest/status.html">status</a></li>
        <li><a href="dart-html/HttpRequest/statusText.html">statusText</a></li>
        <li><a href="dart-html/HttpRequest/timeout.html">timeout</a></li>
        <li><a href="dart-html/HttpRequest/upload.html">upload</a></li>
        <li><a href="dart-html/HttpRequest/withCredentials.html">withCredentials</a></li>
        <li class="inherited"><a href="dart-core/Object/hashCode.html">hashCode</a></li>
        <li class="inherited"><a href="dart-html/EventTarget/on.html">on</a></li>
        <li class="inherited"><a href="dart-html/HttpRequestEventTarget/onAbort.html">onAbort</a></li>
        <li class="inherited"><a href="dart-html/HttpRequestEventTarget/onError.html">onError</a></li>
        <li class="inherited"><a href="dart-html/HttpRequestEventTarget/onLoad.html">onLoad</a></li>
        <li class="inherited"><a href="dart-html/HttpRequestEventTarget/onLoadEnd.html">onLoadEnd</a></li>
        <li class="inherited"><a href="dart-html/HttpRequestEventTarget/onLoadStart.html">onLoadStart</a></li>
        <li class="inherited"><a href="dart-html/HttpRequestEventTarget/onProgress.html">onProgress</a></li>
        <li class="inherited"><a href="dart-html/HttpRequestEventTarget/onTimeout.html">onTimeout</a></li>
        <li class="inherited"><a href="dart-core/Object/runtimeType.html">runtimeType</a></li>
    
        <li class="section-title"><a href="dart-html/HttpRequest-class.html#instance-methods">Methods</a></li>
        <li><a href="dart-html/HttpRequest/abort.html">abort</a></li>
        <li><a href="dart-html/HttpRequest/getAllResponseHeaders.html">getAllResponseHeaders</a></li>
        <li><a href="dart-html/HttpRequest/getResponseHeader.html">getResponseHeader</a></li>
        <li><a href="dart-html/HttpRequest/open.html">open</a></li>
        <li><a href="dart-html/HttpRequest/overrideMimeType.html">overrideMimeType</a></li>
        <li><a href="dart-html/HttpRequest/send.html">send</a></li>
        <li><a href="dart-html/HttpRequest/setRequestHeader.html">setRequestHeader</a></li>
        <li class="inherited"><a href="dart-html/EventTarget/addEventListener.html">addEventListener</a></li>
        <li class="inherited"><a href="dart-html/EventTarget/dispatchEvent.html">dispatchEvent</a></li>
        <li class="inherited"><a href="dart-core/Object/noSuchMethod.html">noSuchMethod</a></li>
        <li class="inherited"><a href="dart-html/EventTarget/removeEventListener.html">removeEventListener</a></li>
        <li class="inherited"><a href="dart-core/Object/toString.html">toString</a></li>
    
        <li class="section-title inherited"><a href="dart-html/HttpRequest-class.html#operators">Operators</a></li>
        <li class="inherited"><a href="dart-core/Object/operator_equals.html">operator ==</a></li>
    
        <li class="section-title"><a href="dart-html/HttpRequest-class.html#static-properties">Static properties</a></li>
        <li><a href="dart-html/HttpRequest/supportsCrossOrigin.html">supportsCrossOrigin</a></li>
        <li><a href="dart-html/HttpRequest/supportsLoadEndEvent.html">supportsLoadEndEvent</a></li>
        <li><a href="dart-html/HttpRequest/supportsOverrideMimeType.html">supportsOverrideMimeType</a></li>
        <li><a href="dart-html/HttpRequest/supportsProgressEvent.html">supportsProgressEvent</a></li>
    
        <li class="section-title"><a href="dart-html/HttpRequest-class.html#static-methods">Static methods</a></li>
        <li><a href="dart-html/HttpRequest/getString.html">getString</a></li>
        <li><a href="dart-html/HttpRequest/postFormData.html">postFormData</a></li>
        <li><a href="dart-html/HttpRequest/request.html">request</a></li>
        <li><a href="dart-html/HttpRequest/requestCrossOrigin.html">requestCrossOrigin</a></li>
    
        <li class="section-title"><a href="dart-html/HttpRequest-class.html#constants">Constants</a></li>
        <li><a href="dart-html/HttpRequest/DONE-constant.html">DONE</a></li>
        <li><a href="dart-html/HttpRequest/HEADERS_RECEIVED-constant.html">HEADERS_RECEIVED</a></li>
        <li><a href="dart-html/HttpRequest/LOADING-constant.html">LOADING</a></li>
        <li><a href="dart-html/HttpRequest/OPENED-constant.html">OPENED</a></li>
        <li><a href="dart-html/HttpRequest/readyStateChangeEvent-constant.html">readyStateChangeEvent</a></li>
        <li><a href="dart-html/HttpRequest/UNSENT-constant.html">UNSENT</a></li>
    
    
    </ol>
  </div><!--/.sidebar-offcanvas-->

  <div id="dartdoc-main-content" class="col-xs-12 col-sm-9 col-md-8 main-content">
      <div><h1><span class="kind-method">request</span> method</h1></div>

    <section class="multi-line-signature">
      <span class="returntype"><a href="dart-async/Future-class.html">Future</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="dart-html/HttpRequest-class.html">HttpRequest</a></span>&gt;</span></span>
            <span class="name ">request</span>
(<wbr><span class="parameter" id="request-param-url"><span class="type-annotation"><a href="dart-core/String-class.html">String</a></span> <span class="parameter-name">url</span>, {</span> <span class="parameter" id="request-param-method"><span class="type-annotation"><a href="dart-core/String-class.html">String</a></span> <span class="parameter-name">method</span>, </span> <span class="parameter" id="request-param-withCredentials"><span class="type-annotation"><a href="dart-core/bool-class.html">bool</a></span> <span class="parameter-name">withCredentials</span>, </span> <span class="parameter" id="request-param-responseType"><span class="type-annotation"><a href="dart-core/String-class.html">String</a></span> <span class="parameter-name">responseType</span>, </span> <span class="parameter" id="request-param-mimeType"><span class="type-annotation"><a href="dart-core/String-class.html">String</a></span> <span class="parameter-name">mimeType</span>, </span> <span class="parameter" id="request-param-requestHeaders"><span class="type-annotation"><a href="dart-core/Map-class.html">Map</a><span class="signature">&lt;<wbr><span class="type-parameter"><a href="dart-core/String-class.html">String</a></span>, <span class="type-parameter"><a href="dart-core/String-class.html">String</a></span>&gt;</span></span> <span class="parameter-name">requestHeaders</span>, </span> <span class="parameter" id="request-param-sendData"><span class="type-annotation">dynamic</span> <span class="parameter-name">sendData</span>, </span> <span class="parameter" id="request-param-onProgress"><span class="type-annotation">void</span> <span class="parameter-name">onProgress</span>(<span class="parameter" id="param-e"><span class="type-annotation"><a href="dart-html/ProgressEvent-class.html">ProgressEvent</a></span> <span class="parameter-name">e</span></span>)</span> })
      
    </section>
    <section class="desc markdown">
      <p>Creates and sends a URL request for the specified <code>url</code>.</p>
<p>By default <code>request</code> will perform an HTTP GET request, but a different
method (<code>POST</code>, <code>PUT</code>, <code>DELETE</code>, etc) can be used by specifying the
<code>method</code> parameter. (See also <a href="dart-html/HttpRequest/postFormData.html">HttpRequest.postFormData</a> for <code>POST</code> 
requests only.</p>
<p>The Future is completed when the response is available.</p>
<p>If specified, <code>sendData</code> will send data in the form of a <a href="dart-typed_data/ByteBuffer-class.html">ByteBuffer</a>,
<a href="dart-html/Blob-class.html">Blob</a>, <a href="dart-html/Document-class.html">Document</a>, <a href="dart-core/String-class.html">String</a>, or <a href="dart-html/FormData-class.html">FormData</a> along with the HttpRequest.</p>
<p>If specified, <code>responseType</code> sets the desired response format for the
request. By default it is <a href="dart-core/String-class.html">String</a>, but can also be 'arraybuffer', 'blob', 
'document', 'json', or 'text'. See also <a href="dart-html/HttpRequest/responseType.html">HttpRequest.responseType</a> 
for more information.</p>
<p>The <code>withCredentials</code> parameter specified that credentials such as a cookie
(already) set in the header or
<a href="http://tools.ietf.org/html/rfc1945#section-10.2">authorization headers</a>
should be specified for the request. Details to keep in mind when using
credentials:</p>
<ul>
<li>Using credentials is only useful for cross-origin requests.</li>
<li>The <code>Access-Control-Allow-Origin</code> header of <code>url</code> cannot contain a wildcard (*).</li>
<li>The <code>Access-Control-Allow-Credentials</code> header of <code>url</code> must be set to true.</li>
<li>If <code>Access-Control-Expose-Headers</code> has not been set to true, only a subset of all the response headers will be returned when calling <code>getAllRequestHeaders</code>.</li>
</ul>
<p>The following is equivalent to the <a href="dart-html/HttpRequest/getString.html">getString</a> sample above:</p>
<pre class="language-dart"><code>var name = Uri.encodeQueryComponent('John');
var id = Uri.encodeQueryComponent('42');
HttpRequest.request('users.json?name=$name&amp;id=$id')
  .then((HttpRequest resp) {
    // Do something with the response.
});
</code></pre>
<p>Here's an example of submitting an entire form with <a href="dart-html/FormData-class.html">FormData</a>.</p>
<pre class="language-dart"><code>var myForm = querySelector('form#myForm');
var data = new FormData(myForm);
HttpRequest.request('/submit', method: 'POST', sendData: data)
  .then((HttpRequest resp) {
    // Do something with the response.
});
</code></pre>
<p>Note that requests for file:// URIs are only supported by Chrome extensions
with appropriate permissions in their manifest. Requests to file:// URIs
will also never fail- the Future will always complete successfully, even
when the file cannot be found.</p>
<p>See also: <a href="http://en.wikipedia.org/wiki/Basic_access_authentication">authorization headers</a>.</p>
    </section>
    
    <section class="summary source-code" id="source">
      <h2><span>Implementation</span></h2>
      <pre class="language-dart"><code class="language-dart">static Future&lt;HttpRequest&gt; request(String url,
    {String method,
    bool withCredentials,
    String responseType,
    String mimeType,
    Map&lt;String, String&gt; requestHeaders,
    sendData,
    void onProgress(ProgressEvent e)}) {
  var completer = new Completer&lt;HttpRequest&gt;();

  var xhr = new HttpRequest();
  if (method == null) {
    method = &#39;GET&#39;;
  }
  xhr.open(method, url, async: true);

  if (withCredentials != null) {
    xhr.withCredentials = withCredentials;
  }

  if (responseType != null) {
    xhr.responseType = responseType;
  }

  if (mimeType != null) {
    xhr.overrideMimeType(mimeType);
  }

  if (requestHeaders != null) {
    requestHeaders.forEach((header, value) {
      xhr.setRequestHeader(header, value);
    });
  }

  if (onProgress != null) {
    xhr.onProgress.listen(onProgress);
  }

  xhr.onLoad.listen((e) {
    var accepted = xhr.status &gt;= 200 &amp;&amp; xhr.status &lt; 300;
    var fileUri = xhr.status == 0; &#47;&#47; file:&#47;&#47; URIs have status of 0.
    var notModified = xhr.status == 304;
    &#47;&#47; Redirect status is specified up to 307, but others have been used in
    &#47;&#47; practice. Notably Google Drive uses 308 Resume Incomplete for
    &#47;&#47; resumable uploads, and it&#39;s also been used as a redirect. The
    &#47;&#47; redirect case will be handled by the browser before it gets to us,
    &#47;&#47; so if we see it we should pass it through to the user.
    var unknownRedirect = xhr.status &gt; 307 &amp;&amp; xhr.status &lt; 400;

    if (accepted || fileUri || notModified || unknownRedirect) {
      completer.complete(xhr);
    } else {
      completer.completeError(e);
    }
  });

  xhr.onError.listen(completer.completeError);

  if (sendData != null) {
    xhr.send(sendData);
  } else {
    xhr.send();
  }

  return completer.future;
}</code></pre>
    </section>

  </div> <!-- /.main-content -->

  <div id="dartdoc-sidebar-right" class="col-xs-6 col-sm-6 col-md-2 sidebar sidebar-offcanvas-right">
  </div><!--/.sidebar-offcanvas-->

</main>

<footer>
  <span class="no-break">
    flutter_form_builder
      3.8.2
  </span>

  <!-- footer-text placeholder -->
</footer>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="static-assets/typeahead.bundle.min.js"></script>
<script src="static-assets/highlight.pack.js"></script>
<script src="static-assets/URI.js"></script>
<script src="static-assets/script.js"></script>
<!-- footer placeholder -->

</body>

</html>
